package com.wuster.controller;


import com.alibaba.fastjson.JSONObject;
import com.wuster.entity.dto.ReportPageDTO;
import com.wuster.entity.vo.FreeTimesVO;
import com.wuster.result.PageResult;
import com.wuster.result.Result;
import com.wuster.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
@Slf4j
public class TeacherController {

    @Autowired
    TeacherService teacherService;


    /**
     * 老师查看打卡记录
     * 老师按姓名查询学生打卡记录
     * @param reportPageDTO   偷懒  使用reportPageDTO接收参数
     * @return
     */
    @PostMapping("/timeManage/clock")
    public Result getClockRecord(@RequestBody ReportPageDTO reportPageDTO){
        log.info("老师查看学生打卡记录....");
        PageResult pageResult = teacherService.getClocks(reportPageDTO.getName(), reportPageDTO.getPageId(), reportPageDTO.getPageSize());
        return Result.success(pageResult);
    }


    /**
     * 老师查看学生信息
     * @param reportPageDTO  偷懒  使用reportPageDTO接收参数
     * @return
     */
    @PostMapping("/studentInfo")
    public Result getStudentInfo(@RequestBody ReportPageDTO reportPageDTO){
        log.info("老师查看学生信息...");
        PageResult pageResult = teacherService.getInfo(reportPageDTO.getName(), reportPageDTO.getPageId(), reportPageDTO.getPageSize());
        return Result.success(pageResult);
    }

    /**
     * 老师查看周报
     * @param reportPageDTO
     * @return
     */
    @PostMapping("/studentReport")
    public Result getStudentReport(@RequestBody ReportPageDTO reportPageDTO){
        log.info("老师查看周报 {}", reportPageDTO);
        PageResult pageResult = teacherService.getStudentReports(reportPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 教师查看空闲
     * @param object
     * @return
     */
    @PostMapping("/studentFrees")
    public Result getStudentFrees(@RequestBody JSONObject object){
        // TODO 解决Post请求接受单个Integer Long 等类型的参数
        log.info("老师查看空闲...");
        List<FreeTimesVO> freeList = teacherService.getFrees(object.getInteger("weekId"));
        return Result.success(freeList);
    }
}
